import merchantConfig from '../../api/merchantConfig'
import * as globalTypes from '../../mutation-types'
export const getECommerceGlobalSet = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.getECommerceGlobalSet(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const getCommodityInfo = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.getCommodityInfo(data)
    .then(response => {
      return response
    })
    .catch(() => {
      // commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const getOrderInfo = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.getOrderInfo(data)
    .then(response => {
      return response
    })
    .catch(() => {
    })
}
export const saveECommerceGlobalSet = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.saveECommerceGlobalSet(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryEcommerceWebchatCfgById = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.queryEcommerceWebchatCfgById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取电商接入网站列表
 * @param data
 * @param data.platform 平台 "web" / app / sdk
 * @returns {*}
 */
export const queryEcommerceWebchat = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.queryEcommerceWebchat(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加一个新的电商网站接入
 * @param data._id 接入网站id
 * @returns {*}
 */
export const addEcommerceWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.addEcommerceWebchatCfg(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const updateEcommerceWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.updateEcommerceWebchatCfg(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除一个网站接入
 * @param data._id 接入网站id
 * @returns {*}
 */
export const deleteEcommerceWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return merchantConfig.deleteEcommerceWebchatCfg(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询营销诊断的数据概况
 * @param data {}
 */
export const newSaveDicItem = ({ commit, state, rootState }, data) => {
  return merchantConfig.newSaveDicItem(data)
    .then(response => {
      return response
    })
    .catch(err => {
      console.error(err)
    })
}
